home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / PATHSTAK.BAT < prev    next >
DOS Batch File  |  1993-06-25  |  2KB  |  64 lines

  1. @echo off
  2. REM ************************************************************************
  3. REM *** PathStak.bat - Utility to save or restore a path location using  ***
  4. REM ***                environment variables to remember.  The paths are ***
  5. REM ***                saved in the PATH_STACK environment variable.     ***
  6. REM ***                Return ERRORLEVEL 0 for success and ERRORLEVEL 1  ***
  7. REM ***                if there was a problem.  No error on restore or   ***
  8. REM ***                forget if there is nothing saved.                 ***
  9. REM ************************************************************************
  10. cd | cenvi %0.bat %1 %2
  11. GOTO CENVI_EXIT
  12.  
  13. main(argc,argv)
  14. {
  15.    if ( 2 != argc ) {
  16.       Instructions();
  17.       Success = False;
  18.    } else {
  19.       Success = True;
  20.       command = argv[1], len = strlen(command);
  21.       // determine how many paths are currently saved
  22.       PathStackDepth = defined(PATH_STACK) ? (GetArraySpan(PATH_STACK) + 1) : 0 ;
  23.       if ( !strnicmp("PUSH",command,len) ) {
  24.          PATH_STACK[PathStackDepth] = gets(); // cd was piped here, which is the current path
  25.       } else if ( !strnicmp("POP",command,len) ) {
  26.          if ( 0 != PathStackDepth ) {
  27.             OldPath = PATH_STACK[PathStackDepth-1];
  28.             // send system calls to return to old path
  29.             system("cd %s",OldPath);
  30.             OldPath[2] = 0;   // get just the <drive>:
  31.             system(OldPath);
  32.             // remove this final element from the PATH_STACK array
  33.             if ( 1 == PathStackDepth ) {
  34.                undefine(PATH_STACK);
  35.             } else {
  36.                SetArraySpan(PATH_STACK,PathStackDepth - 2);
  37.             }
  38.          }
  39.       } else if ( !strnicmp("FORGET",command,len) ) {
  40.          undefine(PATH_STACK);
  41.       } else {
  42.          Instructions();
  43.          Success = False;
  44.       }
  45.    }
  46.    return( Success ? 0 : 1 );
  47. }
  48.  
  49. Instructions()
  50. {
  51.    printf("\a\n")
  52.    printf("PathStak.bat - Save or restore directory paths.\n")
  53.    printf("\n")
  54.    printf("SYNTAX: PathStak PUSH | POP | FORGET\n")
  55.    printf("\n")
  56.    printf("Where:  PUSH    Save the current directory as most recent.\n")
  57.    printf("        POP     Return to the most recently saved directory.\n")
  58.    printf("        FORGET  Forget all saved directories.\n")
  59.    printf("\n")
  60. }
  61.  
  62.  
  63. :CENVI_EXIT
  64.